package club.beimeng.controller;

import club.beimeng.commonutils.R;
import club.beimeng.config.ConifgEntity;
import club.beimeng.service.VideoService;
import club.beimeng.vo.VideoUrlVo;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

@CrossOrigin
@RestController
@RequestMapping("/admin/vod/video")
public class VideoController {

    @Autowired
    private VideoService videoService;


    @ApiOperation("上传视频接口")
    @PostMapping("/upload")
    public R uploadVideo(@ApiParam(value = "上传视频文件",required = true) MultipartFile file){
        // 调用service方法，并返回访问路径
        // 希望之后可以做出一个带有进度条的上传接口
        // !!! el-upload 中接受文件的参数名称必须叫file
        String videoUrl = videoService.uploadVideo(file);
        return videoUrl != null ? R.ok().data("url" , videoUrl) : R.error();
    }

    @ApiOperation("根据视频链接删除视频")
    @DeleteMapping("/removeVideo")
    public R removeVideo(@ApiParam(value = "源视频链接", required = true) @RequestBody VideoUrlVo videoUrlVo){
        String sourceVideoUrl = videoUrlVo.getVideoUrl();
        //这里并不做实际删除，而是将删除了的视频，转移到类似回收站的文件加里面去
        Boolean answer = videoService.removeVideo(sourceVideoUrl);
        return R.ok();
    }
}
/*
 *
 * @author Mr.Bao
 * @date 2021/7/30 20:48
 */